<?php
/*-------------------------------------------------------+
| PHP-Fusion Content Management System
| Copyright (C) 2002 - 2011 Nick Jones
| http://www.php-fusion.co.uk/
+--------------------------------------------------------+
| Filename: tags.php
| Author: Philip Daly (HobbyMan)
+--------------------------------------------------------+
| This program is released as free software under the
| Affero GPL license. You can redistribute it and/or
| modify it under the terms of this license which you
| can read by viewing the included agpl.txt or online
| at www.gnu.org/licenses/agpl.html. Removal of this
| copyright header is strictly prohibited without
| written permission from the original author(s).
+--------------------------------------------------------*/
require_once "../../maincore.php";
require_once THEMES."templates/header.php";
include INFUSIONS."tags_system_panel/infusion_db.php";
include INFUSIONS."tags_system_panel/inc/inc.php";


if (!$_GET['taglist']) { redirect("../../index.php"); } 

$tagname = $_GET['taglist'];

// News
$result = dbquery(
            "SELECT a.tag_id, a.tag_name, a.tag_type, a.tag_tags, u.news_id, u.news_subject, u.news_news 
			FROM ".DB_TAGS." a
			LEFT JOIN ".DB_NEWS." u ON u.news_id=a.tag_name 
			WHERE ".groupaccess('news_visibility')."
			AND a.tag_type = 'N' 
			AND news_draft = '0' 
			ORDER BY news_datestamp 
			DESC
			");                               

opentable($locale['tgs_003'].$locale['global_200'].$tagname);

 echo "<table width='100%' cellpadding='0' cellspacing='1' class='tbl-border'>\n";

if (dbrows($result)) {
 
while ($data = dbarray($result)) {

  if ($data['tag_tags']) {
		$tags = explode(", ", $data['tag_tags']);
		foreach ($tags as $values) {
		
		if ($values == $tagname) {
		     echo "<tr><td class='tbl1'>";
		     echo "<a href='".BASEDIR."news.php?readmore=".$data['news_id']."' title='".$data['news_subject']."' class='side'><strong>".$data['news_subject']."</strong></a>\n<br />";
		     echo stripslashes($data['news_news'])."<hr /></td>\n</tr>\n";
			 }
		   }
		 }
	   }
	 }
	   
// Photos	 

$result = dbquery(
			"SELECT a.tag_id, a.tag_name, a.tag_type, a.tag_tags, u.photo_id, u.album_id, u.photo_title, u.photo_description, u.photo_thumb1, tac.album_id, tac.album_access    
			FROM ".DB_TAGS." a
			LEFT JOIN ".DB_PHOTOS." u ON u.photo_id=a.tag_name 
			INNER JOIN ".DB_PHOTO_ALBUMS." tac ON u.album_id=tac.album_id 
			".(iSUPERADMIN ? "" : " 
			WHERE ".groupaccess('album_access'))." 
			AND a.tag_type = 'P'
			ORDER BY photo_datestamp 
			DESC");

if (dbrows($result)) {
while ($data = dbarray($result)) {
  if ($data['tag_tags']) {
		$tags = explode(", ", $data['tag_tags']);
		foreach ($tags as $values) {
		
		if ($values == $tagname) {
		     echo "<tr><td class='tbl1'>";
		     echo "<a href='".BASEDIR."photogallery.php?photo_id=".$data['photo_id']."' title='".$data['photo_title']."' class='side'><strong>".$data['photo_title']."</strong></a>\n</td></tr>";
		     echo "<tr><td class='tbl1' align='center'>";
		     echo "<a href='".BASEDIR."photogallery.php?photo_id=".$data['photo_id']."' title='".$data['photo_title']."' class='side'>\n";
		     echo "<img src='".IMAGES."photoalbum/album_".$data['album_id']."/".$data['photo_thumb1']."' alt='".$data['photo_title']."' />\n</a></td>\n";
		     echo "<tr><td class='tbl1'>".trimlink($data['photo_description'], 200)."<hr /></td>\n</tr>\n";
			 }
		   }
		 }
	   }
	 }
	   
// Articles

$result = dbquery(
            "SELECT a.tag_id, a.tag_name, a.tag_type, a.tag_tags, u.article_id, u.article_cat, u.article_subject, u.article_snippet, tac.article_cat_id, tac.article_cat_access    
			FROM ".DB_TAGS." a
			LEFT JOIN ".DB_ARTICLES." u ON u.article_id=a.tag_name 
			INNER JOIN ".DB_ARTICLE_CATS." tac ON u.article_cat=tac.article_cat_id 
			".(iSUPERADMIN ? "" : "WHERE ".groupaccess('article_cat_access'))." 
			AND a.tag_type = 'A'
			AND article_draft = '0' 
			ORDER BY article_datestamp 
			DESC");

if (dbrows($result)) {
while ($data = dbarray($result)) {

  if ($data['tag_tags']) {
		$tags = explode(", ", $data['tag_tags']);
		foreach ($tags as $values) {
		
		if ($values == $tagname) {
		     echo "<tr><td class='tbl1'>";
		     echo "<a href='".BASEDIR."articles.php?article_id=".$data['article_id']."' title='".$data['article_subject']."' class='side'><strong>".$data['article_subject']."</strong></a>\n<br />";
		     echo stripslashes($data['article_snippet'])."<hr /></td>\n</tr>\n";
			 }
		   }
		 }
	   }
	 }
	   
// Custom Pages

$result = dbquery(
            "SELECT a.tag_id, a.tag_name, a.tag_type, a.tag_tags, u.page_id, u.page_title, u.page_content   
			FROM ".DB_TAGS." a
			LEFT JOIN ".DB_CUSTOM_PAGES." u ON u.page_id=a.tag_name
			WHERE a.tag_type = 'C'
			AND ".groupaccess('page_access')."
			ORDER BY page_id 
			DESC
			");

if (dbrows($result)) {
while ($data = dbarray($result)) {

  if ($data['tag_tags']) {
		$tags = explode(", ", $data['tag_tags']);
		foreach ($tags as $values) {
		
		if ($values == $tagname) {
		     echo "<tr><td class='tbl1'>";
		     echo "<a href='".BASEDIR."viewpage.php?page_id=".$data['page_id']."' title='".$data['page_title']."' class='side'><strong>".$data['page_title']."</strong></a>\n<br />";
		     echo trimlink(stripinput($data['page_content']), 200)."<hr /></td>\n</tr>\n";
			 }
		   }
		 }
	   }
	 }
	   echo "</table>\n";
     
   closetable();                                  

require_once THEMES."templates/footer.php";
?>